home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: HELP. How to convert '0x12' into FF char?
- Date: Sun, 24 Mar 96 22:56:04 GMT
- Organization: none
- Message-ID: <827708164snz@genesis.demon.co.uk>
- References: <4iissm$s76@nntp.ucs.ubc.ca> <4il52a$ma7@nntp.interaccess.com> <4itj1h$p8e@nntp.ucs.ubc.ca>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4itj1h$p8e@nntp.ucs.ubc.ca>
- gordonw@unixg.ubc.ca "Gordon Wong" writes:
-
- >void filtmoz() {
- >
- > char c,d,e,s[5];
- > c=fgetc(infile);
-
- fgetc() returns an int. c,d,e must be declared as int.
-
- > while (c != EOF) { /* scan file byte by byte */
- >
- > switch (c) {
- > case '+' : c = ' '; fputc(c,outfile); break;
- > case '&' : fputc('\n',outfile); break;
- > case '%' : /* Any % encountered signals an ASCII Char */
- > {
- > d=fgetc(infile);
- > e=fgetc(infile);
-
- Check d and e for EOF.
-
- > sprintf(s, "0x%c%c", d, e);
-
- You don't need the 0x here since the %x specifier below assumes a hexadecimal
- representation.
-
- > sscanf(s,"%x",&c);
-
- %x requires you to pass *scanf a pointer to an unsigned int.
-
- You could replace the last 4 lines with simply:
-
- fscanf(infile, "%2x", &u);
-
- where u is defined as an unsigned int. fscanf also has a return value that
- should be tested - either the number of input items assigned or EOF on
- error.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-